package com.lxk.seckilldemo.utils;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;

import javax.swing.*;

@Component
public class MD5Util {
    public static String md5(String s){
        return DigestUtils.md5Hex(s);
    }
    private static final String salt="1a2b3c4d";
    public static String inputPassToFromPass(String inputPass){
        String str="" + salt.charAt(4)+salt.charAt(0)+inputPass+salt.charAt(3)+salt.charAt(1);
        return md5(str);
    }
    public static String FromPassToDBPass(String FromPass,String salt){
        String str="" + salt.charAt(4)+salt.charAt(0)+FromPass+salt.charAt(3)+salt.charAt(1);
        return md5(str);
    }
    public static String inputPassToDBPass(String inputPass,String salt) {
        String s1 = inputPassToFromPass(inputPass);
        return FromPassToDBPass(s1,salt);
    }

    public static void main(String[] args) {
        String s=MD5Util.inputPassToDBPass("123456","1a2b3c4d");
        String s1=MD5Util.FromPassToDBPass("edc55adff9e3c7b8f82363f90f12f9c3","1a2b3c4d");
        System.out.println(s);
        System.out.println(s1);
    }
}
